<?php
/*
 * 主投方向
 */
namespace App\Models;

use Illuminate\Database\Eloquent\Model;

class UserInvestCategory extends Model
{
    //
    protected $table = 'user_invest_category';

    public $timestamps = false;

    protected $fillable = array('uid', 'category_id');

    public function category()
    {
        return $this->belongsTo('App\Models\Category', 'category_id', 'id');
    }

    /**
     * usercategory 有改动的时候刷新缓存
     * @param unknown_type $user
     */
    static function refreshCache($user){
    	$investCategories=array();
    	if(count($user->userCategories)){
    		foreach($user->userCategories as $k=>$v){
    			$investCategories[$k]['id']=$v->id;
    			$investCategories[$k]['name']=$v->name;
    		}
    	}
    	Cache::forever('user_invest_categories_'.$user->uid, $userCategories,1);
    }
}
